﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bank
{
    // 大额交易事件参数
    public class BigMoneyArgs : EventArgs
    {
        public string Account { get; }
        public double Amount { get; }

        public BigMoneyArgs(string account, double amount)
        {
            Account = account;
            Amount = amount;
        }
    }

    public class Bank
    {
        protected ArrayList accounts = new ArrayList();

        public void AddAccount(Account account)
        {
            accounts.Add(account);
        }

        public virtual bool Register(string account, string password)
        {
            if (FindAccount(account, password) == null)
            {
                AddAccount(new Account(account, password));
                return true;
            }
            else
            {
                return false;
            }
        }

        public Account FindAccount(string id, string pwd)
        {
            foreach (Account account in accounts)
            {
                if (account.login(id, pwd))
                {
                    return account;
                }
            }
            return null;
        }

        public bool CloseAccount(Account target)
        {
            if (accounts.Contains(target))
            {
                accounts.Remove(target);
                return true;
            }
            return false;
        }
    }

    // 信用账户银行类
    public class CreditBank : Bank
    {
        public override bool Register(string account, string password)
        {
            if (FindAccount(account, password) == null)
            {
                AddAccount(new CreditAccount(account, password));
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
